package StudyCode.summary.zipfile;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class DoAGunzipOperation {
	public static byte[] gunzip(byte[] data) {
		ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(10240);
		GZIPInputStream input = null;
		try {
			input = new GZIPInputStream(new ByteArrayInputStream(data));
			byte[] buffer = new byte[1024];
			int n = 0;
			for (; ; ) {
				n = input.read(buffer);
				if (n <= 0)
					break;
				byteOutput.write(buffer, 0, n);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (input != null) {
				try {
					input.close();
				} catch (IOException ioe) {
				}
			}
		}
		return byteOutput.toByteArray();
	}
}
